home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PsL Monthly 1993 December
/
PSL Monthly Shareware CD-ROM (December 1993).iso
/
prgmming
/
dos
/
c
/
pwrclib.exe
/
DIRSELF.C
< prev
next >
Wrap
C/C++ Source or Header
|
1992-10-01
|
17KB
|
482 lines
#include "STDIO.h"
#include "STDLIB.h"
#include "IO.h"
#include "FCNTL.h"
#include "DOS.h"
#include "DIR.h"
/*
DIRSEL.c v1.00 Vernon E. Davis
07/12/87 17 South Centre Street
Merchantville, NJ 08109
CompuServe [71330,2705]
GEnie - VED
Adapted for Power C 2.0.1 by
Chuck Steenburgh [72330,1776]
purpose : to select one filename from the list presented
syntax : #include "STDIO.h"
: #include "STDLIB.h"
: #include "IO.h"
: #include "FCNTL.h"
: #include "DOS.h"
: #include "DIR.h"
: *p = dirselect(*mask,attr);
: char *p; the filename
: char *mask; the directory mask, i.e. "*.*"
: int attr; the attribute to look for,i.e.
: FA_RDONLY, FA_HIDDEN, FA_SYSTEM,
: FA_LABEL, FA_DIREC, FA_ARCH.
: (see dos.h or Turbo C manual for info.)
:
returns : either a pointer to a filename that was selected or
: NULL if Escape was pressed and if no file is found.
:
descrip. : a call to dirselect() first determines if there are any files
: that meet the specs received from the directory mask. If
: no files were found, the function immediately returns NULL.
: Otherwise, all filenames that meet the mask spec are copyed
: into an array that can hold up to 120 selections. The routine
: then clears a portion of the screen, saving the contents of
: the screen in an array. A frame is drawn in the cleared portion
: of the screen and the current directory contents are displayed
: in the boxed area as per the mask that was received. The first
: selection is highlighted in reverse video. The up/down/left/
: right arrow keys will move the highlight around. The Home Key
: returns to the first selection. The End key moves to the last
: selection. When < CR > is pressed, the screen returns to
: normal, the cursor is placed in its original position and the
: value returned from the function is a pointer to a string
: containing the filename selected. If Esc was pressed instead,
: the previous sequence is performed, with the exception of NULL
: being returned instead of the filename.
:
notes : A. All routines in this file can be run under TC, the
: Turbo C Integrated Development Environment. Because of
: this, the routine will run slow when executed. It was
: not designed for speed.
: B. These routines rely on the video hardware interrupt 0x10
: for the cursor information. Insure that the PC is an IBM
: or compatable.
: C. Three (3) cursor functions and a frame drawing function are
: available. They are as follows:
: 1. void gotoxy(x,y); move cursor to new location
: int x (0..79)
: int y (0..24)
: 2. void cursor(ON/OFF); turn cursor on or off
: int ON (1) or OFF (0)
: 3. xyposdef wherecur(void); locate cursor position
: xyposdef.x (0..79) column location
: xyposdef.y (0..24) row location
: 4. void drframe(top,left,bottom,right); draw double fr.
: int top (0..24) top corner
: int left (0..79) left corner
: int bottom (0..24) bottom corner
: int right (0..79) right corner
: The other functions declared are special to dirselect()
: and of no real use; however, they are documented.
*/
#define TRUE 1
#define FALSE 0
#define ON 1
#define OFF 0
#define VIDINTR 0x10
#define EQUINTR 0x11
#define FPOS1 1
#define FPOS2 14
#define FPOS3 27
#define FPOS4 40
#define FPOS5 53
#define FPOS6 66
typedef struct /* structure for directory array */
{ char fname[13];
} dirdef;
typedef struct /* structure for cursor column(x) and row(y) */
{ int x,y;
} xyposdef;
/* function declarations */
char* dirselect(char*,int); /* the main function */
void hilite(unsigned char,unsigned char); /* highlights the filename */
xyposdef fnamepos(unsigned char); /* X/Y position of filename */
void gotoxy(unsigned char,unsigned char); /* move cursor to new location */
void cursor(int); /* turn cursor on or off */
xyposdef wherecur(void); /* current cursor location */
int menubox(int r1, c1, r2, c2, color, boxtype, shadow, shade); /* See file MENUBOX.C */
char* dirselect(mask,attr)
char mask[13];
int attr;
{ union REGS regs;
struct ffblk ffblk;
int h,i,j,k,row,error,oldcurx,oldcury;
unsigned char oldpos,newpos;
char chrbuf[4000],atrbuf[4000];
char key;
dirdef dos_dir[121],*dos_dirptr;
xyposdef xypos;
h=0;
if((error=findfirst(mask,&ffblk,attr))==-1) /* if not found, return NULL */
return(NULL);
while(!error&&h!=120) /* else, collect filenames */
{ dos_dirptr=&dos_dir[h++];
strcpy(dos_dirptr->fname,ffblk.ff_name);
error=findnext(&ffblk);
};
xypos=wherecur(); /* store old cursor position */
oldcurx=xypos.x;
oldcury=xypos.y;
cursor(OFF);
k=0;
for(i=0;i<((h/6)+3);i++) /* store old screen info & clear portion */
{ for(j=0;j<80;j++)
{ gotoxy(j,i);
regs.h.bh=0;
regs.h.ah=8;
int86(VIDINTR,®s,®s);
chrbuf[k]=regs.h.al;
atrbuf[k]=regs.h.ah;
putch(32);
k++;
};
};
gotoxy(0,0);
i=0; j=0; row=1;
while(TRUE) /* display all filenames */
{ dos_dirptr=&dos_dir[i];
xypos=fnamepos(i);
gotoxy(xypos.x,xypos.y);
printf("%-012.12s",dos_dirptr->fname);
i++; j++;
if(i==h||i==120) break;
if(j>5)
{ j=0;
row++;
printf("\n");
};
};
menubox(0,0,(row+1),79,15,3,0,1); /* draw the frame */
hilite(255,0); /* highlight the first filename */
oldpos=0;
newpos=0;
while(TRUE) /* get keypress and do appropriate action */
{ key=getch();
switch(key)
{ case 27: /* Esc */
k=0;
for(i=0;i<((h/6)+3);i++) /* return contents of old screen */
{ for(j=0;j<80;j++)
{ gotoxy(j,i);
regs.h.al=chrbuf[k];
regs.h.bl=atrbuf[k];
regs.h.ch=0;
regs.h.cl=1;
regs.h.bh=0;
regs.h.ah=9;
int86(VIDINTR,®s,®s);
k++;
};
};
gotoxy(oldcurx,oldcury); /* return old cursor position */
cursor(ON);
return(NULL); /* return NULL */
case 71: /* Home */ /* goto first filename */
oldpos=newpos;
newpos=0;
hilite(oldpos,newpos);
break;
case 79: /* End */ /* goto last filename */
oldpos=newpos;
newpos=(h-1);
hilite(oldpos,newpos);
break;
case 72: /* Up */ /* move up one filename */
i=newpos;
i-=6;
if(i>=0)
{ oldpos=newpos;
newpos=i;